package com.atech.ebayadmin.invoice.util;

import java.io.*;
import java.util.Date;
import java.util.List;
import com.atech.ebayadmin.common.ConstConfig;
import com.atech.ebayadmin.common.util.DateUtil;
import com.atech.ebayadmin.common.util.Uuid;
import com.atech.ebayadmin.invoice.model.Invoice;
import jxl.Workbook;
import jxl.write.*;


public class FileCreate {
    public static  String createOrderDetail(List<Invoice> list,String info) throws Exception{
		String path=ConstConfig.contextPath + ConstConfig.excelPath+"/"+Uuid.create().toString32()+".xls";
		try {
	            //打开文件
                WritableWorkbook book = null;
                book = Workbook.createWorkbook(new File(path));
//			    WritableWorkbook book = Workbook.createWorkbook(new File("d:\test.xsl"));\
	            //参数0表示这是第一页
	            WritableSheet sheet = book.createSheet("Invoice Report", 0);
                sheet.addCell(new jxl.write.Label(0, 0, "ItemID"));
                sheet.addCell(new jxl.write.Label(1, 0, "eBay Account"));
                sheet.addCell(new jxl.write.Label(2, 0, "Ref Number"));
                sheet.addCell(new jxl.write.Label(3, 0, "Title"));
                sheet.addCell(new jxl.write.Label(4, 0, "Entry Type"));
	            sheet.addCell(new jxl.write.Label(5, 0, "Currency"));
                sheet.addCell(new jxl.write.Label(6, 0, "Value"));
	            sheet.addCell(new jxl.write.Label(7, 0, "Time"));
                for(int i=0;i<list.size();i++){
                		Invoice invoice = list.get(i);
			            sheet.addCell(new jxl.write.Label(0, i+1, invoice.getItemID()));
			            sheet.addCell(new jxl.write.Label(1, i+1, invoice.getEbayAct()));
			            sheet.addCell(new jxl.write.Label(2, i+1, invoice.getRefNumber()));
			            
			            sheet.addCell(new jxl.write.Label(3, i+1, invoice.getTitle()));
			            sheet.addCell(new jxl.write.Label(4, i+1, invoice.getAccountDetailsEntryType()));
			            
			            sheet.addCell(new jxl.write.Label(5, i+1, invoice.getBalance().getCurrencyID()));
			            sheet.addCell(new jxl.write.Number(6, i+1, invoice.getBalance().getValue()));  
			            Date craeteDate = invoice.getDate().getTime();
			            sheet.addCell(new jxl.write.Label(7, i+1, DateUtil.formatDate(craeteDate, "yyyyMMdd")));
                }
	            //写入数据并关闭文件
	            book.write();
	            book.close();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return path;
	    }
 }

